/*
 * DayButton.java
 *
 * Created on 07/03/2010
 */


package org.calendar.button;




import javax.swing.JToggleButton;

import javax.swing.BorderFactory;
import java.awt.Dimension;
import java.awt.Insets;

import java.awt.event.MouseEvent;

/**
 * This class is a toogle button.
 *
 * @author Julie Duvillier
 */

public class DayButton extends JToggleButton {


    private Dimension dim = new Dimension(26,20);
    private Insets margin = new Insets(0,0,0,0);


    private boolean isToday;
    private boolean isLastMonth;
    private boolean isNextMonth;
    private boolean isCurrentMonth;

    /**
     * Creates a new DayButton.
     */
    public DayButton(){
        setBorderPainted(false);
        setPreferredSize(dim);
        setMargin( margin);

    }

    /**
     * Sets the boolean that represents if the button
     * is today.
     * @param b  true if the button represents today
     */
    public void setToday(boolean b){
        isToday = b;
    
    }
    /**
     * Sets the boolean that represents if the button
     * is a day of last month or not.
     * @param b true if the button represents a day of last month
     */
    public void setLastMonth( boolean b){
        isLastMonth = b;
        if ( isLastMonth ) {
            isNextMonth = false;
            isCurrentMonth = false;
        }
       
    }

    /**
     * Sets the boolean that represents if the button
     * is a day of current month or not.
     * @param b  true if the button represents a day of current month
     */
    public void setCurrentMonth(boolean b){
        isCurrentMonth = b;
        if( isCurrentMonth ){
             isLastMonth = false;
             isNextMonth = false;

        }
    }
    /**
     * Sets the boolean that represents if the button
     * is a day of next month or not.
     * @param b true if the button represents a day of next month
     */
    public void setNextMonth( boolean b){
        isNextMonth =b;
         if ( isNextMonth ){
            isLastMonth = false;
            isCurrentMonth = false;
         }
    }

    /**
     * Determines whether the button represents the current day.
     * @return <code>true</code> if the button represents today,
     *          <code>false</code> otehrwise.
     */
    public Boolean isToday(){
        return isToday;
    }


    /**
     * Determines whether the button represents a day of the last month,
     * comparing from the displayed month.
     * @return <code>true</code> if the button represents  a day of the last month,
     *         <code>false</code> otherwise.
     */
    public Boolean isLastMonth(){
        return isLastMonth;
    }

    /**
     * Determines whether the button represents a day of the next month,
     * comparing from the displayed month.
     * @return <code>true</code> if the button represents  a day of the next month,
     *         <code>false</code> otherwise.
     */
    public Boolean isNextMonth(){
        return isNextMonth;
    }

    /**
     * Determines whether the button represents a day of the displayed month.
     * @return <code>true</code> if the button represents  a day of thedisplayed month,
     *         <code>false</code> otherwise.
     */
    public Boolean isCurrentMonth(){
        return isCurrentMonth;
    }


    /**
     * Processes mouse events occurring on day buttons.
     * @param e the mouse event
     */
   @Override
    protected void processMouseEvent(MouseEvent e) {
        switch ( e.getID() ) {
            case MouseEvent.MOUSE_ENTERED:
                if( ! isSelected() )
                setContentAreaFilled( ! isContentAreaFilled() );
                break;
            case MouseEvent.MOUSE_EXITED:
               if( ! isSelected() )
                    setContentAreaFilled( ! isContentAreaFilled() );
        
                break;
        }
        super.processMouseEvent(e);
    }

}
